<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
	
    public function index(){
    	$goodsModel = D('Admin/goods');
    	//var_dump($goodsModel);die();
    	$goodsData = $goodsModel->getGoods();
    	$cateModel = D('Admin/category');
    	$goodsfloorData = $cateModel->getFloorData();
    	//echo '<pre>';
    	//var_dump($goodsfloorData);die();
    	//echo '<pre>';
    	//var_dump($goodsData);die();
    	$this->assign(array(
    		'goodsData' =>$goodsData,
    		'goodsfloorData'=>$goodsfloorData,

    	));
    	$this->display();
    }
    public function goods(){
    	$id = I('get.id');
    	//var_dump($id);die;
        $goodsModel = D('Admin/goods');
    	$goodsData = $goodsModel->getMemberPrice($id);
    	//var_dump($goodsData);die();
    	//取出商品的信息
    	$info = $goodsModel->find($id);
    	//var_dump($goodsData);die(); 
    	//面包屑导航
    	$categoryModel= D('Admin/Category');
    	//var_dump($categoryModel);die();
    	//$categoryData = $categoryModel->getCatPath($info['cat_id']);
    	//var_dump(categoryData);die();
    	//遍历出评论 的东西
    	$memberModel = D('Admin/member');
    	$name = $memberModel->field('name')->where(array(
    		'id'=>array('eq',session('member_id')),
    	))->find();
    	//var_dump($name);die();
    	$commentModel = D('Admin/Comment');
    	
    	$commentData = $commentModel->where(array(
    		'goods_id'=>$id,
    		
    	))->order('id desc')->select();
    	//var_dump($commentData);die();
    	$this->assign(array(
    		'goodsData'=>$goodsData,
    		'info'    =>$info,
    	    'commentData'=>$commentData,
    		'name'     =>$name,
    	));
    	
    	$this->display();
    }
    public function getAjaxPrice(){
    	$id = I('get.id');
    	$model = D('Admin/goods');
    	$goodsPrice = $model->getMemberPrice($id);
        echo  $goodsPrice;
    	

    	$this->display();
    }
    //先判断能不能用户评论 (购买这件商品才能评论)
    public  function ajaxCheckPinglun(){
    	$member = D('Admin/member');
    	if($member->isBuy(I('goods_id'))){
    		echo 1;
    	}
    }
    //评价提交的内容
   public function ajaxComment()
	{
		$model = D('Admin/Comment');
		//var_dump($model);die();
		if(IS_POST)
		{
			
			
			if($model->create(I('post.'), 1))
			{
				$modelMember = D('Member');
				$info = $modelMember->field('face')->find(session('member_id'));
				if($model->add())
				{
					if($info['face']){
						$face = '/Public/Uploads/'.$info['face'];
					}else{
						$face = '/Public/Home/images/taohua.jpg';
					}
					$this->success(array(
						'face'=>$face,
					), '', TRUE);   // 返回一个AJAX
				}
			}
			$this->error($model->getError(), '', TRUE);
		}
	}
	
}